import Vue from 'vue'
import App from './App.vue'
// 引入vuex
import store from '@/store/index.js'
// 引入vue-router
import router from './router'
Vue.config.productionTip = false
// 实现粒子效果
import VueParticles from '../node_modules/vue-particles'
Vue.use(VueParticles);
// 引入自定义全局样式
import './assets/css/global.css'
// 引入elementUI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// 引入阿里云字体库
import './assets/fonts/iconfont.css'
import './assets/fonts/iconfont.js'
// 引入axios
import axios from 'axios'
// 将axios挂载到vue的实例上，因为在vue2中每个组件都是vue的实例
// 在别的组件中可以使用this.$http发起axios请求
// 在请求头中添加 Authorization 参数，并将 token 添加到 Bearer 后面
axios.interceptors.request.use(
  config => {
    const token = localStorage.getItem('token')
    if (token) {
      config.headers.authorization = `${token}`
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)
axios.defaults.baseURL = '/api'
axios.interceptors.request.use(
  config => {
    const token = localStorage.getItem('token')
    if (token) {
      config.headers.authorization = `${token}`
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)
Vue.prototype.$axios  = axios
Vue.use(ElementUI);
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

